


package yf.mall.controller;
import com.yf.request.SearchParam;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yf.annotation.SysLog;
import yf.mall.entity.MallGoodsEntity;
import yf.mall.service.MallGoodsService;
import yf.mall.vo.LotteryGoodsVo;
import yf.mall.service.LotteryGoodsService;
import com.yf.response.R;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
                                import yf.mall.enums.LotteryGoodsStatusEnum;
                
/**
 * 中奖奖品Controller
 *
 * @author hxf
 * @email 505860922@qq.com
 * @date Thu Aug 20 11:18:45 CST 2020
 */
@RestController
@RequestMapping("/lottery/goods")
public class LotteryGoodsController {
    @Autowired
    private LotteryGoodsService lotteryGoodsService;

    @Autowired
    private MallGoodsService mallGoodsService;

    /**
     * 列表中奖奖品
     */
    @SysLog("查看中奖奖品")
    @RequestMapping("/list")
    @RequiresPermissions("lottery:goods:list")
    public R list(@RequestBody SearchParam<LotteryGoodsVo> params) {
        PageHelper.startPage(params.getPage(), params.getLimit()).setOrderBy(params.getOrder());
        List<LotteryGoodsVo> list = lotteryGoodsService.findVo(params.getEntity());
        List<MallGoodsEntity> goodsList = this.mallGoodsService.findGoods();
        return R.ok(new PageInfo(list)).putExtra("goodsList", goodsList);
    }

    /**
 * 下载订单
 */
    @SysLog("下载订单")
    @RequestMapping("/down")
    @RequiresPermissions("lottery:goods:list")
    public void down(@RequestBody SearchParam<LotteryGoodsVo> params, HttpServletResponse response) {
        List<LotteryGoodsVo> list = lotteryGoodsService.findVo(params.getEntity());
            lotteryGoodsService.downLoad(response, list);
    }


    /**
     * 查看中奖奖品
     */
    @SysLog("查看中奖奖品")
    @RequestMapping("/info/{id}")
    @RequiresPermissions("lottery:goods:info")
    public R info(@PathVariable("id") Long id) {
            LotteryGoodsVo vo = lotteryGoodsService.getVo(id);

        return R.ok(vo);
    }

    /**
     * 保存中奖奖品
     */
    @SysLog("保存中奖奖品")
    @RequestMapping("/save")
    @RequiresPermissions("lottery:goods:save")
    public R save(@RequestBody LotteryGoodsVo vo) {
            lotteryGoodsService.saveVo(vo);
        return R.ok(vo);
    }

    /**
     * 修改中奖奖品
     */
    @SysLog("修改中奖奖品")
    @RequestMapping("/update")
    @RequiresPermissions("lottery:goods:update")
    public R update(@RequestBody LotteryGoodsVo vo) {
            lotteryGoodsService.updateVo(vo);

        return R.ok(vo);
    }

    /**
     * 删除中奖奖品
     */
    @SysLog("删除中奖奖品")
    @RequestMapping("/delete")
    @RequiresPermissions("lottery:goods:delete")
    public R delete(Long[]ids) {
            lotteryGoodsService.deleteBatch(ids);

        return R.ok();
    }

    /**
     * 所有中奖奖品
     */
    @SysLog("所有中奖奖品")
    @RequestMapping("/all")
    public R all(String order) {
        PageHelper.orderBy(order!=null ? order : "id desc");
        List<LotteryGoodsVo> list = lotteryGoodsService.findVo(null);
        return R.ok(list);
    }

    /**
     * 所有enums
     */
    @SysLog("所有enums")
    @RequestMapping("/dmz/options")
    public R options() {
        HashMap<String,Object> options = new HashMap();
                                                                                                                                        options.put("statusOptions",LotteryGoodsStatusEnum.names());
                                                                                        return R.ok(options);
    }





    /***********自定义开始***********/
}
